home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 090 / sampler4.arc / FORECAST.SAC < prev    next >
Text File  |  1985-08-30  |  14KB  |  391 lines

  1. !*******************************************************************!
  2. !                                                                   !
  3. !             Forecasting the Single Equation Model                 !
  4. !                       (Section 9.4)                               !
  5. !                                                                   !
  6. !*******************************************************************!
  7.  
  8. ON ECHO
  9.  
  10. !    Forecasting with SORITEC SAMPLER is accomplished by RECOVERing
  11. !    the fitted equation from SORITEC's internal variables after
  12. !    estimation, changing the USE period to the forecast interval, and
  13. !    executing the FORECAST command.  SAMPLER's forecasting capabilities
  14. !    are demonstrated with an example adapted from R.W. Kopcke,
  15. !    "Forecasting Investment Spending:  The Performance of Statistical
  16. !    Models", New England Economic Review, November/December, 1982.
  17. !
  18. !    In this example, we estimate two of the models evaluated in that
  19. !    study for forecasting investment in nonresidential structures:
  20. !              (1)  The General Accelerator Model
  21. !              (2)  The Time Series Model
  22. !    The General Accelerator Model relates gross private investment in
  23. !    nonresidential structures to gross domestic business product and
  24. !    net stocks of nonresidential structures.  The Time Series Model
  25. !    relates the ratio of gross private investment and net stocks of
  26. !    residential structures lagged by one period to the ratio from the
  27. !    previous period.  Independent variables in both equations are
  28. !    lagged several periods back.
  29. !
  30. !    This example differs from the Kopcke study in both the data and
  31. !    estimator used to estimate the equations.  Identical results
  32. !    should therefore not be expected.
  33. !    The equations are estimated from 1954q1 to 1977q4;  forecasts are
  34. !    evaluated over the 1978q1 to 1980q4 period.  Since independent
  35. !    variables are lagged several quarters back, data from 1951q1 are
  36. !    read into SORITEC SAMPLER.  Data definitions are:
  37. !
  38. !                     qpi = gross private investment in nonresidential
  39. !                           structures 
  40. !                    gdbp = gross domestic business product
  41. !           nonres_stocks = net stocks of nonresidential structures
  42. !
  43. !    All data are expressed in 1972 dollars.
  44. !
  45.  
  46. USE  1951Q1    1981Q4       
  47. READ         qpi           gdbp        nonres_stocks   
  48.             20.4         290.37         212.285       
  49.             21.1         293.18         214.449
  50.             21.0         297.06         216.341
  51.             20.1         299.83         218.194
  52.             20.2         301.93         219.826
  53.             20.4         299.83         221.699
  54.             20.6         301.60         223.370
  55.             21.4         317.93         225.434
  56.             22.0         325.07         227.386
  57.             22.5         328.88         229.658
  58.             22.6         326.74         231.688
  59.             23.1         314.62         234.039
  60.             23.5         312.10         236.217
  61.             23.7         311.91         238.645
  62.             23.7         315.90         241.038
  63.             23.7         325.03         243.397
  64.             24.5         339.87         245.919
  65.             25.0         349.06         248.528
  66.             25.9         353.77         251.319
  67.             26.4         360.03         254.194
  68.             27.3         360.79         257.508
  69.             28.4         362.50         260.792
  70.             28.8         360.41         264.128
  71.             28.8         367.20         267.685
  72.             28.5         370.94         270.855
  73.             28.5         369.76         274.255
  74.             28.4         368.58         277.312
  75.             28.3         361.67         280.301
  76.             27.9         347.20         283.434
  77.             26.9         346.27         285.997
  78.             26.2         357.20         288.349
  79.             26.4         372.40         290.718
  80.             26.3         385.87         293.028
  81.             27.2         399.29         295.824
  82.             28.0         391.06         298.487
  83.             27.9         393.59         301.390
  84.             29.3         409.83         304.301
  85.             29.0         406.35         307.404
  86.             29.2         400.68         310.212
  87.             30.6         396.69         313.639
  88.             30.6         398.89         316.711
  89.             30.1         408.79         319.935
  90.             30.1         415.73         322.800
  91.             29.9         428.45         325.900
  92.             30.4         438.04         328.901
  93.             31.6         441.13         332.159
  94.             32.7         446.08         335.980
  95.             31.9         448.65         339.221
  96.             30.6         454.69         342.094
  97.             32.1         465.28         345.299
  98.             32.3         471.39         348.509
  99.             32.8         476.69         351.799
  100.             32.8         488.96         355.044
  101.             34.3         495.49         358.615
  102.             35.1         503.30         362.336
  103.             35.6         507.50         366.129
  104.             37.6         525.09         370.736
  105.             40.7         532.16         375.689
  106.             40.9         539.42         380.623
  107.             43.4         553.87         386.110
  108.             43.8         566.45         391.620
  109.             43.2         571.17         396.507
  110.             44.1         576.32         401.937
  111.             42.7         580.54         406.942
  112.             42.8         581.53         411.490
  113.             41.7         584.79         416.103
  114.             41.9         591.29         420.701
  115.             41.5         599.63         425.136
  116.             43.0         608.77         429.881
  117.             42.4         620.19         434.411
  118.             42.1         631.16         438.803
  119.             43.6         639.04         443.507
  120.             44.1         645.39         448.269
  121.             44.5         648.75         453.064
  122.             45.9         653.08         458.140
  123.             45.4         650.00         463.021
  124.             44.2         643.46         467.535
  125.             44.3         644.90         472.012
  126.             43.9         650.64         476.327
  127.             43.3         640.70         480.433
  128.             43.2         660.25         484.456
  129.             42.9         662.96         488.349
  130.             43.0         670.16         491.721
  131.             42.3         680.18         495.353
  132.             43.5         698.07         499.232
  133.             43.9         711.45         503.156
  134.             44.0         720.35         507.051
  135.             45.2         739.28         511.188
  136.             45.9         759.64         515.442
  137.             47.3         757.51         520.504
  138.             48.3         758.00         525.235
  139.             47.9         763.59         529.801
  140.             46.6         755.51         533.973
  141.             45.2         756.38         538.278
  142.             41.8         751.28         541.691
  143.             40.8         739.88         544.278
  144.             38.6         720.60         546.828
  145.             37.6         733.36         548.556
  146.             38.3         755.08         550.984
  147.             38.5         766.15         552.889
  148.             39.2         790.39         555.494
  149.             39.4         793.51         557.014
  150.             39.8         800.75         559.159
  151.             39.5         805.49         561.198
  152.             38.9         823.77         563.059
  153.             40.2         849.78         565.219
  154.             41.3         870.62         567.622
  155.             41.2         873.84         570.535
  156.             41.9         877.78         572.455
  157.             44.7         903.70         575.605
  158.             45.7         909.09         578.960
  159.             46.2         920.95         582.393
  160.             46.6         924.03         585.295
  161.             48.2         918.39         588.539
  162.             50.4         922.38         592.268
  163.             51.2         919.65         596.127
  164.             50.9         928.33         600.218
  165.             48.4         908.49         603.854
  166.             47.5         910.13         607.217
  167.             48.3         923.83         610.731
  168.             50.4         940.97         614.867      
  169.             52.3         942.98         619.351
  170.             55.0         948.08         624.448
  171.             55.1         928.47         629.499
  172.     ;
  173. END
  174.  
  175. !
  176. !    As the Time Series Model requires both the dependent and independent
  177. !    variables to be expressed as ratios, transform the variables before
  178. !    estimating the model.
  179. !
  180.  
  181. USE 1954q1 1981q4
  182.  
  183. lag_0 = qpi(0)/nonres_stocks(-1)
  184. lag_1 = qpi(-1)/nonres_stocks(-1)
  185. lag_2 = qpi(-2)/nonres_stocks(-1)
  186. lag_3 = qpi(-3)/nonres_stocks(-1)
  187.  
  188. !
  189. !    Define names for the transformed variables in a GROUP statement.
  190. !
  191.  
  192. GROUP tsm_vars lag_0 lag_1 lag_2 lag_3
  193. ON GROUP
  194.  
  195. !
  196. !    Now estimate the Time Series Model using OLS.
  197. !
  198.  
  199. REGRESS tsm_vars
  200.  
  201. OFF GROUP
  202.  
  203. !
  204. !    In order to forecast, we must recover the fitted equation which is
  205. !    stored as a SORITEC internal variable under the name, ^FOREQ.
  206. !    Also, we want to recover rho, which measures the autocorrelation
  207. !    between residual terms.  Rho is stored as the first element of the
  208. !    internal SORITEC variable ^AUTOCOR and is used correct the
  209. !    raw forecast data as was done in the Kopcke article.
  210. !
  211.  
  212. RECOVER tsm_fitted FOREQ
  213. SET tsm_rho = ^AUTOCOR(1)
  214.  
  215. !
  216. !    Now estimate the General Accelerator Model over the 1954q1 to 1977q4
  217. !    period.  Note that in this specification, gross domestic business
  218. !    product is lagged from t=0 to t=-5. These can be specified quite
  219. !    simply in SORITEC as shown in the command line.  Again, OLS is used
  220. !    to estimate the model
  221. !
  222.  
  223. REGRESS qpi gdbp(0 to -5) nonres_stocks(-1)
  224.  
  225. !
  226. !    Again, RECOVER the fitted equation and rho.
  227. !
  228.  
  229. RECOVER gam_fitted FOREQ
  230. SET gam_rho = ^AUTOCOR(1)
  231.  
  232. !
  233. !    The important thing to remember when FORECASTing a fitted equation is
  234. !    that the original dependent variable is replaced by forecast values of
  235. !    the dependent variable over the period being forecast.  Because of this,
  236. !    it is advisable either to databank the original data series (remember,
  237. !    all observations will be saved regardless of the active USE period), or
  238. !    copy the original series into another via a transformation, i.e.,
  239. !
  240.  
  241. USE  1951Q1    1981Q4       
  242. qpi_original = qpi
  243.  
  244. !
  245. !    Now adjust the USE period to the period over which forecasts are to 
  246. !    be made.
  247. !
  248.  
  249. USE 1978q1 1981q4
  250.  
  251. !
  252. !    Then simply forecast the dependent variable for each model.
  253. !
  254. !        (1) For the Time Series Model:
  255. !
  256.  
  257. FORECAST tsm_fitted
  258.  
  259. !
  260. !    Transform the dependent variable for the Time Series Model back into
  261. !    gross private investment in nonresidential structures.
  262. !
  263.  
  264. qpi_tsm = lag_0 * nonres_stocks(-1)
  265.  
  266. !    
  267. !        (2) For the General Accelerator Model:
  268. !
  269.  
  270. FORECAST gam_fitted
  271.      
  272. !
  273. !    Copy the forecast dependent variable into qpi_gam (for consistencey).
  274. !
  275.  
  276. qpi_gam = qpi
  277.  
  278. !
  279. !    Print out the original and two forecast values for gross private
  280. !    investment in nonresidential structures.
  281. !
  282.  
  283. PRINT qpi_original qpi_tsm qpi_gam
  284.  
  285. !
  286. !    Plot the original data and the two forecast estimates.
  287. !         Let qpi_original = O
  288. !                  qpi_tsm = T
  289. !                  qpi_gam = G
  290. !
  291.  
  292. PLOT qpi_original O qpi_tsm T qpi_gam G
  293.  
  294. !
  295. !    Correct the raw forecast error by subtracting the product of the
  296. !    raw forecast error from the previous quarter and the equations
  297. !    autocorrelation coefficient (rho) from the raw forecast error
  298. !    for the current quarter.  (Set the 1977q4 values of qpi_tsm and
  299. !    qpi_gam to the actual values, first.  Note that you must REVISE
  300. !    the series or the forecast values will be wiped out.)
  301. !
  302.  
  303. USE 1977q4
  304.  
  305. REVISE qpi_tsm = qpi_original
  306. REVISE qpi_gam = qpi_original
  307.  
  308. USE 1978q1 1981q4
  309.  
  310. tsm_error = (qpi_original - qpi_tsm) &
  311.                     - tsm_rho * (qpi_original(-1) - qpi_tsm(-1))
  312.  
  313. gam_error = (qpi_original - qpi_gam) &
  314.                     - gam_rho * (qpi_original(-1) - qpi_gam(-1))
  315.  
  316. !
  317. !    Now calculate error statistics similar to those in the Kopcke
  318. !    article: 
  319. !    
  320. !    (1) mean error 
  321. !    
  322.  
  323. DOT tsm_error gam_error
  324. SUM error_sum :
  325. SET mean_: = error_sum/16
  326. ENDDOT
  327.  
  328. !    
  329. !    (2) mean absolute error
  330. !    
  331.  
  332. DOT tsm_error gam_error
  333. abs_: = abs(:)
  334. SUM error_sum abs_:
  335. SET mean_abs_: = error_sum/16
  336. ENDDOT
  337.  
  338. !    
  339. !    (3) root mean square error.
  340. !    
  341.  
  342. DOT tsm_error gam_error
  343. squared_: = : ** 2
  344. SUM error_sum squared_:
  345. SET mean_squared_: = (error_sum/16)**0.5
  346. ENDDOT
  347.  
  348. !    
  349. !    Write out results in formatted form and compare to Kopcke results
  350. !    
  351. !    First enter Kopcke results, as vectors.
  352. !    
  353.  
  354. VECTOR gam_vec .57 1.0 1.1
  355. VECTOR tsm_vec .52 1.1 1.3
  356.  
  357. !    
  358. !    Set up the format statements
  359. !    
  360.  
  361. 100  FORMAT(/////15x,&
  362.             'Error Statistics for Static Forecasts of Investment Models')
  363. 101  FORMAT(31x,'1978Q1 to 1981Q4')
  364. 102  FORMAT(11x,'Estimated Results',25x,'Kopcke Results')
  365. 103  FORMAT(2(17x,'Mean',7x,'Root Mean',2x),/,2(4x,'Mean',7x,'Absolute', &
  366.             6x,'Squared',3x)/6(4x,'Error',4x)/)
  367. 104  FORMAT(6(f9.2,4x))
  368. 105  FORMAT(' General Accelerator Model')
  369. 106  FORMAT(' Time Series Model')
  370.  
  371. !    
  372. !    Write out the results.  Since we don't want the results written
  373. !    out after each command (the commands and output would be intermixed),
  374. !    disable the ECHO option with the OFF ECHO command.  This simply turns
  375. !    off the printing of input lines to the output device.
  376. !    
  377.  
  378. OFF ECHO
  379. WRITE(100)
  380. WRITE(101)
  381. WRITE(102)
  382. WRITE(103)
  383. WRITE(105)
  384. WRITE(104) mean_gam_error mean_abs_gam_error mean_squared_gam_error gam_vec
  385. WRITE(106)
  386. WRITE(104) mean_tsm_error mean_abs_tsm_error mean_squared_tsm_error tsm_vec
  387. ON ECHO
  388. QUIT
  389.  
  390.